'use client';

import { useSearchParams } from 'next/navigation';
import React, { useEffect } from 'react';
import Image from 'next/image';

function Redirect() {
  const searchParams = useSearchParams();
  const backUrl = searchParams.get('backurl') || '/';
  const isHide = searchParams.get('hide');
  const delayMs = Number(searchParams.get('delayMs')) || 150;

  useEffect(() => {
    setTimeout(() => (window.location.href = backUrl), delayMs * 1);
  }, [backUrl, delayMs]);

  return (
    <div
      className={`redirect-page flex flex-col items-center justify-center mt30 ${isHide ? 'invisible' : ''}`}
    >
      <h2 className="fs26 mb20">
        <Image
          src="/nextasset/images/redirect.png"
          width={50}
          height={50}
          style={{
            display: 'inline-block',
            verticalAlign: 'middle',
            width: '30px',
            marginRight: '10px',
          }}
          alt="redirect"
        />
        <span className="ttl-text">Redirecting</span>
      </h2>
      <p className="fs18">
        You are being redirected to
        <a href={backUrl} className="underline font-normal ml5 mr5">
          {backUrl}
        </a>
        , please wait...
      </p>
      <div className="spinner"></div>
    </div>
  );
}

export default Redirect;
